#include <stdlib.h>
#include <stdio.h>
#include <common.h>

int main(int argc, char ** argv, char ** envp)
{
#if 0
    // test reverser_sentence
    if (argc < 2) {
	fprintf(stderr, "Usage: cCommon sentence\n");
	return -1;
    }
    char * r = NULL;
    printf("original sentence:##%s##\n", argv[1]);
    r = reverse_sentence(argv[1]);
    printf("reversed sentence:##%s##\n", r);
    free(r);
#endif

#if 0
    // test transpose_matrix
    int m[10] = {1,2,3,4,5,6,7,8,9,0};
    int trans[10];
    int row = 2, col = 5;
    printf("original matrix:\n");
    print_matrix(m, row, col);
    transpose_matrix(m, row, col, trans);
    printf("transposed matrix:\n");
    print_matrix(trans, col, row);
#endif

#if 0
    // test statements and declarations of gnu c extensions with macro count_ones
    int x; 
    if (argc < 2) {
	fprintf(stderr, "Usage: cCommon arg1");
	return -1;
    }

    x = atoi(argv[1]);
    printf("integer to be checked: "); print_bstr(x);
    printf("\nones: %d\n", count_ones(x));
    printf("integer after checking: "); print_bstr(x);
#endif

#if 0
    // test find_dup: find whether duplicate elements exist in a[n] with elements between 1 and n
    int a[] = {1,3,8,2,4,4,7,5};
    int size = sizeof(a) / sizeof(a[0]);
    int res;

    if (-1 == (res = find_dup(a,size)))
	printf("no duplicate elements\n");
    else
	printf("%d duplicates\n", res); 
#endif

    // test compact: compact a sorted array to make each element unique. return the new length of array, otherwise -1 for error. 
    //int a[] = {1,3,8,2,4,4,7,5};
    int a[] = {1,3,3,7,8,8,8};
    //int a[] = {1,1,2,2};
    int size = sizeof(a) / sizeof(a[0]);
    int res;

    print_array(a, size);
    if (-1 == (res = compact(a,size)))
	printf("compact array: error\n");
    else
	printf("new length: %d\n", res); 
    print_array(a, res);

    return 0;
}
